﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CoolCode.Controls
{
    public delegate void OnConfirm(ConfirmEventArgs result);

    public enum ConfirmResult
    {
        No,
        Yes
    }

    public class ConfirmEventArgs : RoutedEventArgs
    {
        public ConfirmResult Value { get; set; }

        public ConfirmEventArgs()
            : base()
        {
        }

        public readonly static ConfirmEventArgs Yes = new ConfirmEventArgs { Value = ConfirmResult.Yes };

        public readonly static ConfirmEventArgs No = new ConfirmEventArgs { Value = ConfirmResult.No };

        public  static bool operator ==(ConfirmEventArgs r1, ConfirmEventArgs r2)
        {
            return r1.Value == r2.Value;
        }

        public  static bool operator !=(ConfirmEventArgs r1, ConfirmEventArgs r2)
        {
            return r1.Value != r2.Value;
        }
    }

    public partial class Confirm : UserControl
    {
        private OnConfirm onConfirm;

        public Confirm(string msg, OnConfirm onConfirm)
        {
            InitializeComponent();
            this.msg.Text = msg;
            this.onConfirm += onConfirm;
            this.confirmPanel.OnClose += new RoutedEventHandler(this.ClosePanel);
            //this.mask.MouseLeftButtonDown += new MouseButtonEventHandler(mask_MouseLeftButtonDown);
            this.btnYes.Click += new RoutedEventHandler(confirm_Click);
            this.btnNo.Click += new RoutedEventHandler(confirm_Click);
        }

        void confirm_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
            if (this.onConfirm != null)
            {
                onConfirm((sender as Button).Name == this.btnYes.Name ? ConfirmEventArgs.Yes : ConfirmEventArgs.No);
            }
        }

        public void ClosePanel(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        //void mask_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        //{
        //    this.Visibility = Visibility.Collapsed;
        //}
    }
}
